import { Component, OnInit, ComponentFactoryResolver, OnDestroy } from '@angular/core';
import { NzMessageService, NzModalSubject } from 'ng-zorro-antd';
import { HttpClient, HttpRequest, HttpHeaders } from '@angular/common/http';
import { RequestMapping } from '../request.mapping';
import { ResultList } from '../result-list';

@Component({
  selector: 'app-message-form',
  templateUrl: './message-form.component.html',
  styleUrls: ['./message-form.component.css']
})
export class MessageFormComponent implements OnInit{

  message={};
  uploading = false;

  constructor(public messageService: NzMessageService,
    public httpClient:HttpClient,
    public modalSubject:NzModalSubject) { }

  ngOnInit() {
  }

  onSubmit(){
    this.uploading = true;
    const headers = new HttpHeaders()
    this.httpClient
    .post<ResultList>(RequestMapping.SEND_MESSAGES_SIMPLE_MESSAGE,this.message,{headers:headers})
    .toPromise().then((response=>{
      if(response.status == 200){
        this.messageService.success("信息发送成功",{nzDuration:3000});
        setTimeout(1000);
        this.uploading = false;
        //退出这个表单页面
        this.modalSubject.destroy();
      }
    }))
   

  }

}

